<html>
<head>
	<script type="text/javascript">
		var aJaxURL			= "server-side/report/sale.action.php";		//server side folder url
		var list_aJaxURL	= "server-side/report/sale/list.action.php";	//server side folder url
		var tName			= "report";												//table name
		
		$(document).ready(function () {        	
			LoadTable(0, 0);
			GetDate("search_start");
			GetDate("search_end");
			SetEvents("", "", "", tName, "get-dialog" , aJaxURL);	
			
		});
        
		function LoadTable(start, end){
			var total = [2,3,4];
			/* Table ID, aJaxURL, Action, Colum Number, Custom Request, Hidden Colum, Menu Array */
			GetDataTable(tName, aJaxURL, "get_list", 5, "start=" + start + "&end=" + end, 0, "", 1, "desc", total);
		}

		function LoadDialog(form,id, amount){
			var buttons = {										        
		        "cancel": {
	                text: "დახურვა",
	                id: "cancel-dialog",
	                click: function () {
	                	$(this).dialog("close");
	                }
	            }
			};
			GetDialog("get-dialog" , 800, "auto",buttons);
			var total = [3,4,5];
			var start 	= $("#search_start").val();
			var end		= $("#search_end").val();			
			var id 		= $("#client_id").val();
			GetDataTable("prod_list", list_aJaxURL, "get_list", 6, "start=" + start + "&end=" + end + "&client_id=" + id, 0, "", 1, "desc", total);	

		    $("#" + "prod_list" + " tbody").on("dblclick", "tr", function () {
		        var nTds = $("td", this);
		        var empty = $(nTds[0]).attr("class");

		        if (empty != "dataTables_empty") {
		            var rID = $(nTds[0]).text();

		            $.ajax({
		                url: list_aJaxURL,
		                type: "POST",
		                data: "act=get_letter&id=" + rID,
		                dataType: "json",
		                success: function (data) {
		                    if (typeof (data.error) != "undefined") {
		                        if (data.error != "") {
		                            alert(data.error);
		                        } else {
			                        
		                        	 $("#get-letter-dialog").html(data.page);	                        
		                			var buttons = {										        
		                			        "cancel": {
		                		                text: "დახურვა",
		                		                id: "cancel-dialog",
		                		                click: function () {
		                		                	$(this).dialog("close");
		                		                }
		                		            }
		                			};		                        
		                        	GetDialog("get-letter-dialog" , 700, "auto", buttons);
		                        }
		                    }
		                }
		            });
		        }
		    });
				
		}

	    $(document).on("change", "#search_start", function () {
	    	var start	= $(this).val();
	    	var end		= $("#search_end").val();
	    	LoadTable(start, end);
	    });
	    
	    $(document).on("change", "#search_end", function () {
	    	var start	= $("#search_start").val();
	    	var end		= $(this).val();
	    	LoadTable(start, end);
	    });

    </script>
</head>

<body>    
    <div id="dt_example" class="ex_highlight_row">
        <div id="container">
            <div id="dynamic">
            	<h2 align="center">გაყიდვები</h2>
            	<div id="button_area">
	            	<div class="left" style="width: 250px;">
	            		<label for="search_start" class="left" style="margin: 5px 0 0 9px;">დასაწყისი</label>
	            		<input type="text" name="search_start" id="search_start" class="inpt right" style="padding: 0px !important; height: 25px !important;"/>
	            	</div>
	            	<div class="right" style="width: 250px;">
	            		<label for="search_end" class="left" style="margin: 5px 0 0 9px;">დასასრული</label>
	            		<input type="text" name="search_end" id="search_end" class="inpt right" style="padding: 0px !important; height: 25px !important;"/>
            		</div>
            	</div>
                <table class="display" id="report">
                    <thead>
                        <tr id="datatable_header">
                            <th>ID</th>
                            <th style="width: 56%;">კლიენტი</th>
                            <th class="min">თანხა</th>
                            <th class="min">თვითღირებულება</th>
                           	<th class="min">სხვაობა</th>
                        </tr>
                    </thead>
                    <thead>
                        <tr class="search_header">
                            <th class="colum_hidden">
                            	<input type="text" name="search_id" value="ფილტრი" class="search_init" />
                            </th>
                            <th>
                            	<input type="text" name="search_number" value="ფილტრი" class="search_init">
                            </th>
                            <th>
                                <input type="text" name="search_date" value="ფილტრი" class="search_init" />
                            </th>
                            <th>
                                <input type="text" name="search_phone" value="ფილტრი" class="search_init" />
                            </th>
                            <th>
                                <input type="text" name="search_category" value="ფილტრი" class="search_init" />
                            </th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <th>&nbsp;</th><th>
                            <p align="right">ჯამი:<br/>სულ ჯამი:</th>
                            <th>&nbsp;</th>
                            <th>&nbsp;</th>
                            <th>&nbsp;</th>
                        </tr>
                    </tfoot>
                </table>
            </div>
            <div class="spacer">
            </div>
        </div>
    </div>
    <div id="get-dialog" class="form-dialog" title="ბარათები">
    	<!-- aJax -->
	</div>
	<div id="get-letter-dialog" class="form-dialog" title="ბარათები">
    	<!-- aJax -->
	</div>
</body>
</html>